import java.text.SimpleDateFormat;
import java.util.Date;

//通过 sleep()方法实现输出当前时间
public class ThreadSleepDemo02  {

    public static void main(String[] args) throws InterruptedException {
        Date currentTime = new Date(System.currentTimeMillis());  //获取系统当前时间
        while(true){
            Thread.sleep(1000);      //每隔1s,打印当前时间
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(currentTime));
            currentTime=new Date(System.currentTimeMillis());  //更新当前时间
        }
    }

}
